package com.blog.tags;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import com.blog.dto.User;

public class LoginTag extends TagSupport{
	//在userManage.jsp 中使用
	@Override
	public int doStartTag() throws JspException {
		try {
			pageContext.getOut().println("hello");
			HttpSession session = pageContext.getSession();
			User user = (User) session.getAttribute("user");
			if(user == null) {
				HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
				((HttpServletResponse)pageContext.getResponse()).sendRedirect(request.getContextPath()+"/home/login.jsp");
				return Tag.SKIP_BODY;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return Tag.SKIP_BODY;
	}
	
	@Override
	public int doEndTag() throws JspException {
		return Tag.SKIP_BODY;
	}





}
